home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_333 / multiplot / source / mplot_src / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  145 lines

  1. /*      _main.c         Copyright (C) 1985  Lattice, Inc.       */
  2.  
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include <ios1.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <workbench/startup.h>
  9. #include <libraries/dos.h>
  10. #include <libraries/dosextens.h>
  11. #include <proto/dos.h>
  12. #include <proto/exec.h>
  13.  
  14. #define MAXARG 32              /* maximum command line arguments */
  15. #define QUOTE  '"'
  16.  
  17. #define isspace(c)      ((c == ' ')||(c == '\t') || (c == '\n'))
  18.  
  19. #ifndef TINY
  20. extern int _fmode,_iomode;
  21. extern int (*_ONBREAK)();
  22. extern int CXBRK();
  23. #endif
  24.  
  25. extern struct UFB _ufbs[];
  26. int argc;                       /* arg count */
  27. char **targv, *argv[MAXARG];     /* arg pointers */
  28.  
  29. #define MAXWINDOW 40
  30. extern struct WBStartup *WBenchMsg;
  31.  
  32. /**
  33. *
  34. * name         _main - process command line, open files, and call "main"
  35. *
  36. * synopsis     _main(line);
  37. *              char *line;     ptr to command line that caused execution
  38. *
  39. * description   This function performs the standard pre-processing for
  40. *               the main module of a C program.  It accepts a command
  41. *               line of the form
  42. *
  43. *                       pgmname arg1 arg2 ...
  44. *
  45. *               and builds a list of pointers to each argument.  The first
  46. *               pointer is to the program name.  For some environments, the
  47. *               standard I/O files are also opened, using file names that
  48. *               were set up by the OS interface module XCMAIN.
  49. *
  50. **/
  51. void _main(line)
  52. register char *line;
  53. {
  54. register char **pargv;
  55. register int x;
  56. struct Process *process;
  57. struct FileHandle *handle;
  58.  
  59. /*
  60. *
  61. * Build argument pointer list
  62. *
  63. */
  64. while (argc < MAXARG)
  65.         {
  66.         while (isspace(*line))  line++;
  67.         if (*line == '\0')      break;
  68.         pargv = &argv[argc++];
  69.         if (*line == QUOTE)
  70.                 {
  71.                 *pargv = ++line;  /* ptr inside quoted string */
  72.                 while ((*line != '\0') && (*line != QUOTE)) line++;
  73.                 if (*line == '\0')  _exit(1);
  74.                 else                *line++ = '\0';  /* terminate arg */
  75.                 }
  76.         else            /* non-quoted arg */
  77.                 {
  78.                 *pargv = line;
  79.                 while ((*line != '\0') && (!isspace(*line))) line++;
  80.                 if (*line == '\0')  break;
  81.                 else                *line++ = '\0';  /* terminate arg */
  82.                 }
  83.         }  /* while */
  84. targv = (argc == 0) ? (char **)WBenchMsg : (char **)&argv[0];
  85.  
  86.  
  87. /*
  88. *
  89. * Open standard files
  90. *
  91. */
  92. #ifndef TINY
  93.  
  94. if (argc == 0)          /* running under workbench      */
  95.         {
  96.         _ufbs[0].ufbfh = NULL;
  97.         _ufbs[1].ufbfh =  Open("Nil:",MODE_NEWFILE);
  98.         _ufbs[1].ufbflg = UFB_NC;
  99.         _ufbs[2].ufbfh = _ufbs[1].ufbfh;
  100.         _ufbs[2].ufbflg = UFB_NC;
  101.         handle = (struct FileHandle *)(_ufbs[0].ufbfh << 2);
  102.         process = (struct Process *)FindTask(0);
  103.         process->pr_ConsoleTask = (APTR)handle->fh_Type;
  104.         x = 0;
  105.         }
  106. else                    /* running under CLI            */
  107.         {
  108.         _ufbs[0].ufbfh = Input();
  109.         _ufbs[1].ufbfh = Output();
  110.         _ufbs[2].ufbfh = Open("Nil:", MODE_NEWFILE);
  111.         x = UFB_NC;                     /* do not close CLI defaults    */
  112.         }
  113.  
  114. _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  115. _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  116. _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  117.  
  118. x = (_fmode) ? 0 : _IOXLAT;
  119. stdin->_file = 0;
  120. stdin->_flag = _IOREAD | x;
  121. stdout->_file = 1;
  122. stdout->_flag = _IOWRT | x;
  123. stderr->_file = 2;
  124. stderr->_flag = _IORW | x;
  125.  
  126. /*      establish control-c handler */
  127.  
  128. _ONBREAK = CXBRK;
  129.  
  130. #endif
  131.  
  132. /*
  133. *
  134. * Call user's main program
  135. *
  136. */
  137.  
  138. main(argc,targv);              /* call main function */
  139. #ifndef TINY
  140. exit(0);
  141. #else
  142. _exit(0);
  143. #endif
  144. }
  145.